/**
 * 
 */
package com.app.service.vo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author yuxk
 *
 */
@SuppressWarnings("serial")
public class DNAVo extends BaseVoImpl {
	private static final String SPILT_STRING=";";
	/**
	 * 
	 */
	public DNAVo() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * 具体dna数据
	 */
	private Map<String,Integer> values = new LinkedHashMap<String,Integer>();
	
	private long pointsum;
	
	/**
	 * dna编号系统给定编号
	 */
	private String dnaCoder;
	
	/**
	 * dna名称
	 */
	private String dnaName;
	
	/**
	 * dna类型
	 */
	private String dnatype;
	
	/**
	 * dna来源
	 */
	private String dnasource;
	
	/**
	 * 具体存放数据库key：默认为主数据库
	 */
	private String dbkey = "main";
	
	private String dnaData;
	
	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		return 0;
	}

	public Map<String, Integer> getValues() {
		return values;
	}

	public void setValues(Map<String, Integer> values) {
		this.values = values;
	}

	public String getDnaCoder() {
		return dnaCoder;
	}

	public void setDnaCoder(String dnaCoder) {
		this.dnaCoder = dnaCoder;
	}

	public String getDnaName() {
		return dnaName;
	}

	public void setDnaName(String dnaName) {
		this.dnaName = dnaName;
	}

	public String getDnatype() {
		return dnatype;
	}

	public void setDnatype(String dnatype) {
		this.dnatype = dnatype;
	}

	public String getDbkey() {
		return dbkey;
	}

	public void setDbkey(String dbkey) {
		this.dbkey = dbkey;
	}

	public long getPointsum() {
		return pointsum;
	}

	public void setPointsum(long pointsum) {
		this.pointsum =  pointsum;
	}
	
	public void setPointsum(int point)
	{
		this.pointsum += point;
	}

	@Override
	public String toString() {
		return "DNAVo [values=" + values + ", pointsum=" + pointsum
				+ ", dnaCoder=" + dnaCoder + ", dnaName=" + dnaName
				+ ", dnatype=" + dnatype + ", dbkey=" + dbkey + "]";
	}

	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((dbkey == null) ? 0 : dbkey.hashCode());
		result = prime * result
				+ ((dnaCoder == null) ? 0 : dnaCoder.hashCode());
		result = prime * result + ((dnaName == null) ? 0 : dnaName.hashCode());
		result = prime * result + ((dnatype == null) ? 0 : dnatype.hashCode());
		result = prime * result + (int) (pointsum ^ (pointsum >>> 32));
		result = prime * result + ((values == null) ? 0 : values.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		DNAVo vo = (DNAVo)obj;
		if(vo.getPointsum()==this.pointsum)
		{
			return true;
		}
		return false;
	}

	@Override
	public Object clone(){
		// TODO Auto-generated method stub
		DNAVo vo = null;
		try {
			File file = new File(System.getProperty("user.dir")+"\\a.txt");
			ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(file));
			output.writeObject(this);
			output.close();
			ObjectInputStream input = new ObjectInputStream(new FileInputStream(file));
			vo = (DNAVo) input.readObject();
			input.close();
			file.delete();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return vo;
	}
	
	public String getPointMsg()
	{
		StringBuilder sb = new StringBuilder("");
		List<String> list = new ArrayList<String>(this.values.keySet());
		Collections.sort(list);
		int i=0;
		for(String k:list)
		{
			i++;
			sb.append(k);
			sb.append("&nbsp;<a href=\"#\" t1='"+k+"' t2='"+this.values.get(k)+"' class=\"sss\" title=\"\">"+this.values.get(k)+"</a>&nbsp;&nbsp;&nbsp;");
			if(i%4==0){
				sb.append("<br>");
			}
			
		}
		return sb.toString();
	}

	public String getDnasource() {
		return dnasource;
	}

	public void setDnasource(String dnasource) {
		this.dnasource = dnasource;
	}

	public String getDnaData() {
		StringBuffer sb=new StringBuffer();
		Set<String> set=values.keySet();
		for(String s:set){
			sb.append(values.get(s)+SPILT_STRING);
		}
		return sb.toString();
	}

	
	
}
